package org.suyafei.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.suyafei.manager.LinkGroupManager;
import org.suyafei.mapper.LinkGroupMapper;
import org.suyafei.model.LinkGroupDO;

import java.util.List;

/**
 * @author 宿某人
 * @Date: 2021/12/17/5:17 下午
 * @Description:
 */
@Component
public class LinkGroupManagerImpl implements LinkGroupManager {

    @Autowired
    private LinkGroupMapper linkGroupMapper;
    @Override
    public int add(LinkGroupDO linkGroupDO) {
        return linkGroupMapper.insert(linkGroupDO);
    }

    @Override
    public int del(Long groupId,Long accountNo) {
        int rows = linkGroupMapper.delete(new QueryWrapper<LinkGroupDO>().eq("id", groupId).eq("account_no", accountNo));
        return rows;
    }


    @Override
    public LinkGroupDO detail(Long groupId, Long accountNo) {
        LinkGroupDO linkGroupDO = linkGroupMapper.selectOne(new QueryWrapper<LinkGroupDO>().eq("id", groupId).eq("account_no", accountNo));
        return linkGroupDO;

    }

    @Override
    public List<LinkGroupDO> listAllLinkGroup(Long accountNo) {
        List<LinkGroupDO> linkGroupDOList = linkGroupMapper.selectList(new QueryWrapper<LinkGroupDO>().eq("account_no", accountNo));
        return linkGroupDOList;
    }

    @Override
    public int updateById(LinkGroupDO linkGroupDO) {
        int rows = linkGroupMapper.update(linkGroupDO, new QueryWrapper<LinkGroupDO>().eq("id", linkGroupDO.getId()).eq("account_no", linkGroupDO.getAccountNo()));
        return rows;
    }
}
